home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / terms / kermit / b / ckmpri.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-30  |  5.5 KB  |  250 lines

  1. /* $Id: ckmpri.c,v 1.5 91/12/15 23:17:46 rick Exp $
  2.  * $Source: /uw/mackermit/RCS/ckmpri.c,v $
  3.  *------------------------------------------------------------------
  4.  * $Log:    ckmpri.c,v $
  5.  * Revision 1.5  91/12/15  23:17:46  rick
  6.  * ut9
  7.  * 
  8.  * Revision 1.4  91/10/13  13:44:33  rick
  9.  * UT(7)
  10.  * 
  11.  * Revision 1.3  91/10/03  12:43:06  rick
  12.  * UT(5)
  13.  * 
  14.  *------------------------------------------------------------------
  15.  * $Endlog$
  16.  */
  17.  
  18. /*
  19.  * file ckmpri.c
  20.  *
  21.  * Module of mackermit containing code for handling printing.  This code was
  22.  * originally put into ckmusr by John A. Oberschelp of Emory U.
  23.  *
  24.  */
  25.  
  26. /*
  27.   Copyright (C) 1985, 1992, Trustees of Columbia University in the City of New
  28.   York.  Permission is granted to any individual or institution to use this
  29.   software as long as it is not sold for profit.  This copyright notice must be
  30.   retained.  This software may not be included in commercial products without
  31.   written permission of Columbia University.
  32. */
  33.  
  34. #include "ckcdeb.h"
  35. #include "ckcker.h"
  36.  
  37. #include "ckmdef.h"        /* General Mac defs */
  38. #include "ckmres.h"        /* Mac resource equates */
  39. #include "ckmasm.h"        /* new A8 and A9 traps */
  40. #include "ckmcon.h"        /* for fonts */
  41. #include "ckmptp.h"        /* ckm* Prototypes */
  42.  
  43.  
  44. int        to_printer = FALSE;
  45. int        to_screen = TRUE;
  46. int        printer_is_on_line_num;
  47. Handle    hPrintBuffer = 0L;
  48. long    lPrintBufferSize;
  49. long    lPrintBufferChars;
  50. long    lPrintBufferAt;
  51.  
  52. extern    MenuHandle menus[];    /* handle on our menus */
  53.  
  54. DialogPtr    printingDialog;
  55. DialogPtr    bufferingDialog;
  56. DialogPtr    overflowingDialog;
  57. DialogPtr    overflowedDialog;
  58. DialogPtr    pauseDialog;
  59.  
  60. #define MIN(a,b) ((a)<(b))?(a):(b)
  61. #define MAX(a,b) ((a)>(b))?(a):(b)
  62.  
  63. void
  64. now_print()
  65. {
  66.     short itemhit;
  67.     long index, length;
  68.     /* CursHandle watchcurs; */
  69.  
  70.     if (lPrintBufferChars >= lPrintBufferSize) {
  71.         overflowedDialog = GetNewDialog(OVERFLOWEDBOXID, NILPTR,
  72.                         (WindowPtr) - 1);
  73.         circleOK(overflowedDialog);
  74.  
  75.         ModalDialog ((ModalFilterProcPtr) NILPROC, &itemhit);
  76.         DisposDialog(overflowedDialog);
  77.         if (itemhit == 2)    /* if Cancel */
  78.             return;
  79.         if (itemhit == 3) {
  80.             DisposHandle(hPrintBuffer);
  81.             hPrintBuffer = 0L;
  82.             lPrintBufferChars = 0L;
  83.             updatepstat();
  84.             return;
  85.         }
  86.     }
  87.  
  88.     if (lPrintBufferChars > lPrintBufferSize) {    /* if buffer wrapped */
  89.         length = lPrintBufferSize;
  90.         index = lPrintBufferAt;
  91.     } else {
  92.         length = lPrintBufferChars;
  93.         index = 0L;
  94.     }
  95.     printer(hPrintBuffer, length, index, lPrintBufferSize);
  96.  
  97.     DisposHandle(hPrintBuffer);
  98.     hPrintBuffer = 0L;
  99.     lPrintBufferChars = 0L;
  100.     updatepstat();
  101. }
  102.  
  103.  
  104. /*
  105.  * printer
  106.  * h - handle to text to print
  107.  * length - number of chars in buffer
  108.  * index - starting index in buffer
  109.  * limit - buffer limit (to wrap index)
  110.  */
  111. printer (Handle h, long length, long index, long limit)
  112. {
  113.     char    PrintBufferChar;
  114.     CursHandle    watchcurs;
  115.     int        typeOfDriver;
  116.     int        chrExtra;
  117.     int        leftMargin;
  118.     GrafPtr    oldPort;
  119.     int        temp;
  120.     TPPrPort    myPrPort;
  121.     THPrint    PrintStuff;
  122.     TPrStatus    myStRec;
  123.  
  124.     PrintStuff = (THPrint)NewHandle(sizeof(TPrint));
  125.     GetPort(&oldPort);
  126.     PrOpen();
  127.     if (PrError() == noErr) {
  128.         temp = PrValidate(PrintStuff);
  129.         temp = PrJobDialog(PrintStuff);
  130.         if (!temp) {
  131.             PrClose();
  132.             SetPort(oldPort);
  133.             return;
  134.         }
  135.         printingDialog = GetNewDialog(PRINTINGBOXID, NILPTR,
  136.                           (WindowPtr) - 1);
  137.         DrawDialog (printingDialog);
  138.         watchcurs = GetCursor(watchCursor);
  139.         SetCursor(*watchcurs);
  140.  
  141.         myPrPort = PrOpenDoc(PrintStuff, nil, nil);
  142.         typeOfDriver = ((*PrintStuff)->prStl.wDev) >> 8;
  143.         if (typeOfDriver == 3) { /*laser*/
  144.             TextFont(courier);
  145.             TextSize(10);
  146.             chrExtra = 0;
  147.             leftMargin = 36;
  148.         } else {
  149.             TextFont(VT100FONT);
  150.             TextSize(9);
  151.             chrExtra = 1;
  152.             leftMargin = 36;
  153.         }
  154.  
  155.         printer_is_on_line_num = 1;
  156.         PrOpenPage(myPrPort, nil);
  157.         MoveTo(leftMargin, 1 * 12);
  158.  
  159.         do {
  160.             if (PrError() != noErr) 
  161.                 break;
  162.             PrintBufferChar = (*h)[index];
  163.             switch (PrintBufferChar) {
  164.               case 13:
  165.                 if (++printer_is_on_line_num > 60) {
  166.                     PrClosePage(myPrPort);
  167.                     PrOpenPage(myPrPort, nil);
  168.                     printer_is_on_line_num = 1;
  169.                 }
  170.                 MoveTo(leftMargin, printer_is_on_line_num * 12);
  171.               break;
  172.  
  173.               case 14:
  174.                 if (printer_is_on_line_num != 1) {
  175.                     PrClosePage(myPrPort);
  176.                     PrOpenPage(myPrPort, nil);
  177.                     printer_is_on_line_num = 1;
  178.                 }
  179.                 MoveTo(leftMargin, printer_is_on_line_num * 12);
  180.               break;
  181.  
  182.               default:
  183.                 DrawChar(PrintBufferChar);
  184.                 Move(chrExtra, 0);
  185.               break;
  186.             }
  187.  
  188.             if (++index == limit)        /* if time to wrap buffer */
  189.                 index = 0L;
  190.  
  191.         } while (--length);
  192.         PrClosePage(myPrPort);
  193.  
  194.         PrCloseDoc(myPrPort);
  195.         if ((PrError() == noErr) &&
  196.             ((**PrintStuff).prJob.bJDocLoop == bSpoolLoop))
  197.             PrPicFile(PrintStuff, nil, nil, nil, &myStRec);
  198.         if ((PrError() != noErr) && (PrError() != 128)) {
  199.             printerr ("Printer error: ", PrError());
  200.         }
  201.  
  202.         DisposDialog(printingDialog);
  203.     }
  204.     PrClose();
  205.     SetPort(oldPort);
  206.     InitCursor();
  207. }
  208.  
  209.  
  210. void
  211. pr_stat()
  212. {
  213.     DialogPtr    printDialog;
  214.     Str255    arg1, arg2, arg3;
  215.     short    itemhit;
  216.  
  217.  
  218.     printDialog = GetNewDialog(PRINTBOXID, NILPTR, (WindowPtr) - 1);
  219.     circleOK(printDialog);
  220.  
  221.     NumToString(MAX(lPrintBufferChars - lPrintBufferSize, 0L), arg1);
  222.     NumToString(MIN(lPrintBufferSize, lPrintBufferChars), arg2);
  223.     NumToString(lPrintBufferSize, arg3);
  224.     ParamText (arg1, arg2, arg3, "");
  225.  
  226.     do {
  227.     ModalDialog ((ModalFilterProcPtr) NILPROC, &itemhit);
  228.  
  229.     switch (itemhit) {
  230.       case 1:
  231.       case 2:
  232.       case 3:
  233.       break;
  234.  
  235.     }
  236.     } while (itemhit > 3);
  237.  
  238.     DisposDialog(printDialog);
  239. }
  240.  
  241.  
  242. /*
  243.  * Junk so Emacs will set local variables to be compatible with Mac/MPW.
  244.  * Should be at end of file.
  245.  * 
  246.  * Local Variables:
  247.  * tab-width: 4
  248.  * End:
  249.  */
  250.